<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Modules_position_m extends Base_model {
	public $primary_key = 'mpos_id';
	
	
	function get_module($widget_id) {
		$widget_id = (int) $widget_id;
		$this->load->model('modules_m','modules');
		if(!$widget_id) 
			return null;
		
		$widget = $this->get($widget_id);
		if (!$widget) 
			return null;
			
		$module = $this->modules->get($widget->module_id);
		return $module;
	}
	
	
	public function gets_widget($position = '', $layout_id = '') {
		$this->db->order_by("mpos_order asc");
		if($position !='')
		$this->db->where("mpos_position",$position);
		if($layout_id !='')
		$this->db->where("layout_id",$layout_id);
		$this->db->from($this->_table . ' as mp');
		
		$this->db->join('modules as m', 'mp.module_id = m.module_id');
		$widgets = $this->db->get()->result();
		$result = array();
		if ($widgets)
		foreach ($widgets as $widget) {
			if (!isset($result[$widget->mpos_position]))
			$result[$widget->mpos_position] = array();
			unset($widget->mpos_config);
			$result[$widget->mpos_position][] = $widget;
		}
		return $result;
	}
	
}

?>